package com.dexilaonian.adpter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.engine.Resource;
import com.dexilaonian.R;
import com.dexilaonian.activity.Person_bindActivity;
import com.dexilaonian.bean.Person_BindBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/8/10.
 */

public class BindPersonAdapter extends BaseAdapter{

    private  Context mContext;
    private  List<Person_BindBean> mPersonList;
    private int mPostiont;

    public BindPersonAdapter(Context context, List<Person_BindBean> person_bindBeen) {
        mContext = context;
        mPersonList = person_bindBeen;
    }

    @Override
    public int getCount() {
        return mPersonList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_bind, null);
            viewHolder.itemPersonBind = (TextView) convertView.findViewById(R.id.item_person_bind);
            viewHolder.itemPersonNews = (TextView) convertView.findViewById(R.id.item_person_news);
            viewHolder.itemPersoniv = (ImageView) convertView.findViewById(R.id.item_person_iv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        String realName = mPersonList.get(position).getRealName();
        String bmi_status = mPersonList.get(position).getBMI_STATUS();
        if (!TextUtils.isEmpty(realName)) {
            viewHolder.itemPersonBind.setText(realName);
        }
        if (!TextUtils.isEmpty(bmi_status)) {
            viewHolder.itemPersonNews.setText(bmi_status);
        }
        if (mPostiont == position) {
            viewHolder.itemPersoniv.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.yes));
        }else {
            viewHolder.itemPersoniv.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.no));
        }
        return convertView;
    }

    public void addChance(int position) {
        mPostiont = position;
    }

    class ViewHolder{
        TextView itemPersonBind;
        TextView itemPersonNews;
        ImageView itemPersoniv;
    }
}
